package com;

/**
 * 合并线程,把多线程变成单线程
 * 
 * join()
 * 
 * @author lenovo
 * @date 2020年7月24日
 */
public class Thread_04_Join {

	public static void main(String[] args) throws InterruptedException {
		Thread t = new Processor5();
		Thread t2 = new Processor5();
		t.setName("t1");
		t2.setName("t2");
		t.start();
		t2.start();

		// 让当前 main 线程,等待 t1 线程执行完之后在执行

		t.join();

		for (int i = 0; i < 10; i++) {
			System.out.println(Thread.currentThread().getName() + "-->" + i);
			Thread.sleep(500);
		}
	}

}

class Processor5 extends Thread {
	@Override
	public void run() {
		int count = 10;
		if (getName().equals("t2")) {
			count = 100;
		}
		for (int i = 0; i < count; i++) {
			System.out.println(getName() + "-->" + i);
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}